package com.fin.zw.aiqas.controller;

import com.fin.zw.aiqas.annotation.CurrentUser;
import com.fin.zw.aiqas.model.request.ReviewTaskRequest;
import com.fin.zw.aiqas.model.request.ReviewTaskToDetailRequest;
import com.fin.zw.aiqas.model.response.InspectionDetailQueryResponse;
import com.fin.zw.aiqas.model.response.ReviewTaskResponse;
import com.fin.zw.aiqas.model.session.SessionModel;
import com.fin.zw.aiqas.service.ReviewTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;


/**
 * @Description:
 * @Author: ZhangGQ
 * @Date: 2019/9/10 10:04
 */
@RestController
@RequestMapping("/reviewtask")
@Api(value = "复核任务管理", description = "复核任务管理")
public class ReviewTaskController {

    @Autowired
    private ReviewTaskService reviewTaskService;

    @PostMapping("/add")
    @ApiOperation(value = "增加复核任务", notes = "增加复核任务")
    public ResponseEntity<Void> addReviewTask(@RequestBody ReviewTaskRequest request, @ApiIgnore @CurrentUser SessionModel sessionModel) {
        reviewTaskService.addReviewTask(request, sessionModel);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/fetchNum")
    @ApiOperation(value = "增加复核任务时根据条件查询对应数量", notes = "增加复核任务时根据条件查询对应数量")
    public ResponseEntity<Integer> fetchNum(ReviewTaskRequest request) {
        Integer integer = reviewTaskService.fetchNum(request);
        return ResponseEntity.ok().body(integer);
    }

    @GetMapping("/fetchPage")
    @ApiOperation(value = "复核任务分页查询", notes = "复核任务分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query", value = "第几页（0 ... N）"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query", value = "每页的大小"),
            @ApiImplicitParam(name = "sort", dataType = "string", paramType = "query", allowMultiple = true, value = "排序：属性名（xxx，asc|desc）"),
    })
    public ResponseEntity<Page<ReviewTaskResponse>> fetchPage(ReviewTaskRequest request, Pageable pageable, @ApiIgnore @CurrentUser SessionModel sessionModel) {
        Page<ReviewTaskResponse> reviewTaskResponses = reviewTaskService.fetchPage(request, pageable, sessionModel);
        return ResponseEntity.ok().body(reviewTaskResponses);
    }

    @GetMapping("/fetch/{id}")
    @ApiOperation(value = "根据ID查询复核任务的基本信息", notes = "根据ID查询复核任务的基本信息")
    public ResponseEntity<ReviewTaskResponse> fetch(@PathVariable Long id) {
        ReviewTaskResponse reviewTaskResponse = reviewTaskService.fetchById(id);
        return ResponseEntity.ok().body(reviewTaskResponse);
    }

    /**
     * @param request
     * @param pageable
     * @return
     */
    @GetMapping("/fetchByIdToDetailPage")
    @ApiOperation(value = "根据复核任务ID查询详情中的任务数量明细", notes = "根据复核任务ID查询详情中的任务数量明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query", value = "第几页（0 ... N）"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query", value = "每页的大小"),
            @ApiImplicitParam(name = "sort", dataType = "string", paramType = "query", allowMultiple = true, value = "排序：属性名（xxx，asc|desc）"),
    })
    public ResponseEntity<Page<InspectionDetailQueryResponse>> fetchByIdToDetailPage(ReviewTaskToDetailRequest request, Pageable pageable) {
        Page<InspectionDetailQueryResponse> inspectionDetailQueryResponses = reviewTaskService.fetchByIdToDetailPage(request, pageable);
        return ResponseEntity.ok().body(inspectionDetailQueryResponses);
    }
}
